<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('单位查询列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
								<label>年度：</label>
								<select name="params[nd]" id="nd">
									<option th:each="nd : ${ndlist}" th:text="${nd}" th:value="${nd}" th:selected="${nd==year}"> </option>
								</select>
							</li>
                            <li >
								<label>月份： </label><select name="params[yf]" id="yf">
								    <option th:each="yf : ${yflist}" th:text="${yf}" th:value="${yf}" th:selected="${yf==term}"></option>
								</select>
							</li>
                            <li>
								<label>报表类型： </label><select id="zbh" name="params[zbh]" >
									<option th:each="dict : ${zbh}" th:text="${dict.zbmc}" th:value="${dict.zbh}" th:selected="${dict.zbh}"></option>
								</select>
							</li>
                             <li style="width:265px">
                                <label>起始单位：</label> 
				                    <div class="input-group"> 
				                        <input class="form-control" type="text" ondblclick="selectHsdwTree()" id="sdwbm" name="params[sdwbm]">
				                        <span class="input-group-addon"><i class="fa fa-search" onclick="selectHsdwTree()"></i></span>
				                    </div> 
                            </li>
                            <li style="width:265px">
                                <label>终止单位：</label> 
				                    <div class="input-group"> 
				                        <input class="form-control" type="text" ondblclick="selectEHsdwTree()" id="edwbm" name="params[edwbm]">
				                        <span class="input-group-addon"><i class="fa fa-search" onclick="selectEHsdwTree()"></i></span>
				                    </div> 
                            </li>
                            <li>
                                <label style="width:100px">清除为零的项：</label>
                                <input type="checkbox" name="params[iszero]" />
                            </li>
                            <li>
                                <a class="btn btn-success btn-rounded btn-sm" onclick="searchPre()"><i class="fa fa-search"></i>&nbsp;查询</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="listdwcxdy()"><i class="fa fa-edit"></i>&nbsp;定义</a>
                                
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="exportExcel()" shiro:hasPermission="system:dwcx:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table">
                 <table class="table table-hover " id="datalistview">
                 </table>	  
		    </div> 
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript"> 
        var prefix = ctx + "system/dwcx";
        
        /*核算单位-新增-选择父部门树*/
        function selectHsdwTree() {
            var options = {
                title: '核算单位选择',
                width: "380",
                url: ctx + "system/hsdw/selectHsdwTree/",
                callBack: dohsdwSubmit
            };
            $.modal.openOptions(options);
        }

        function dohsdwSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
               $("#sdwbm").val(body.find('#treeId').val());
               layer.close(index);
        }
        
        /*核算单位-新增-选择父部门树*/
        function selectEHsdwTree() {
            var options = {
                title: '核算单位选择',
                width: "380",
                url: ctx + "system/hsdw/selectHsdwTree/",
                callBack: doEndhsdwSubmit
            };
            $.modal.openOptions(options);
        }

        function doEndhsdwSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
               $("#edwbm").val(body.find('#treeId').val());
               layer.close(index);
        }

    	function searchPre() {
			var config = {
        	        url: prefix+"/list",
        	        type: "post",
        	        dataType: "json",
        	        data: $('#formId').serialize(),
        	        beforeSend: function () {
        	        	$.modal.loading("正在处理中，请稍后...");
        	        },
        	        success: function(result) {
        	        	$.modal.closeLoading();
        	        	
        	        	if (result.code!=0){
        	        		$.modal.msgWarning(result.msg);
        	        	}else{
        	        		showData(result);
        	        	}
        	        }
        	    };
        	    $.ajax(config);
		}
    	
    	 function showData(result){
         	$("#datalistview").empty(); //清空列表
         	var list=result.subrows;
         	var cols=0;
         	for(var i=0; i<list.length; i++) { 
 				var zbhData = list[i];
 				if (zbhData["sfxs"]=='1'){
 					cols=cols+1;
 				}	 
 			}
         	var totalCols=cols+2;
         	
         	var pageStr=[];	
         	
         	pageStr.push("<thead>"); 
         	pageStr.push("<tr>"); 
           	pageStr.push("<td align='center' style='font-size:22px;font-weight:bold; height:28px; border:#808080 1px solid;' colspan='"+totalCols+"'>"+$("#zbh").find("option:selected").text()+"</td>"); 
         	pageStr.push("</tr>"); 
         	
         	pageStr.push("<tr>"); 
           	pageStr.push("<td align='left' style='font-size:14px; height:28px; border:#808080 1px solid;' colspan='2'>编报时间:</td>"); 
           	pageStr.push("<td align='right' style='font-size:14px; height:28px; border:#808080 1px solid;' colspan='"+cols+"' >单位：元</td>"); 
         	pageStr.push("</tr>"); 
         	pageStr.push("<tr>"); 
         	pageStr.push("<th align='center' style='font-size:14px; height:28px; border:#808080 1px solid;' width='5%'>单位编码</th>"); 
         	pageStr.push("<th align='center' style='font-size:14px; height:28px; border:#808080 1px solid;' width='10%'>单位名称</th>");  
 			for(var i=0; i<list.length; i++) { 
 				var zbhData = list[i];
 				if (zbhData["sfxs"]=='1'){
					pageStr.push("<th align='center' style='font-size:14px; height:28px; border:#808080 1px solid;' width='5%'>"+zbhData["xsmc"]+"</th>");
 				}		 
 			}
 			pageStr.push("</tr>"); 
 			pageStr.push("</thead>"); 
 			pageStr.push("<tbody>");
 			var datalist=result.rows;
 			for(var i=0; i<datalist.length; i++) { 
 				var vData = datalist[i];
 				pageStr.push("<tr>"); 
 				pageStr.push("<td align='left' style='font-size:14px; height:28px; border:#808080 1px solid;' width='5%'>&nbsp;"+vData["dwbm"]+"</td>"); 
 				pageStr.push("<td style='font-size:14px; height:28px; border:#808080 1px solid;'>"+vData["dwmc"]+"</td>"); 
 				var map=vData["map"];
				$.each(map,function(key,value){
					if (value==0){
						pageStr.push("<td align='right' style='font-size:14px; height:28px; border:#808080 1px solid;' width='5%'></td>");	
					}else{
						pageStr.push("<td align='right' style='font-size:14px; height:28px; border:#808080 1px solid;' width='5%'>"+value+"</td>");
					}
				});
 				pageStr.push("</tr>"); 
 			}
 			pageStr.push("</tbody>");
 			var viewStr=pageStr.join("");
         	$("#datalistview").append(viewStr);
         	
         }
    	 searchPre();
    	 
    	 function listdwcxdy() {
 		    var url = ctx + 'system/dwcxdy';
 		    $.modal.openFull("单位查询定义", url, '800', '540');
 		}
    	 
    	 function exportExcel() {
 		    var url = prefix + '/export';
 			var config = {
        	        url: url,
        	        type: "post",
        	        dataType: "json",
        	        data: $('#formId').serialize(),
        	        beforeSend: function () {
        	        	$.modal.loading("正在生成导出文件，请稍后...");
        	        },
        	        success: function(result) {
        	        	$.modal.closeLoading();
        	        	window.location.href=ctx + "common/download?fileName="+result.filename+"&delete=true";
        	        	layer.msg('下载进行中请稍后…', { icon: 1 });
        	        	
        	        }
        	};
        	$.ajax(config);
 		}
    </script>
</body>
</html>